<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:if test="keywords.keywordsId==null"><s:text name="keywords.add.title"/></s:if><s:else><s:text name="keywords.edit.title"/></s:else></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
</head>
<body>
<div class="wrapper">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/welcome.action"><s:text name="homepage"/></a><span>></span><s:text name="keywords.title"/></div>
	<div class="listtit"><p><span><strong><s:if test="keywords.keywordsId==null"><s:text name="keywords.add.title"/></s:if><s:else><s:text name="keywords.edit.title"/></s:else></strong></span></p></div>
	<div class="listadd">
		<s:form action="keywords-save" onsubmit="return chkform()">
		<s:hidden name="keywords.keywordsId"/>
		<table class="addgrid">
			<tr>
				<th width="20%"><span style="color:red;">*</span><s:text name="keywords.keywords"/>:</th>
				<td>
				<s:textfield name="keywords.keywords" onblur="chk_words()" maxlength="20" cssClass="txtin"/>
				<span style="color:red" id="span_keywords"></span>
				</td>				
			</tr>
			<tr>
				<th><span style="color:red;">*</span><s:text name="keywords.firstLetter"/>:</th>
				<td><s:textfield name="keywords.firstLetter" maxlength="10" cssClass="txtin"/>
				<span style="color:red" id="span_firstLetter"></span>
				</td>
			</tr>
			<tr>
				<th><span style="color:red;">*</span><s:text name="keywords.pinyin"/>:</th>
				<td><s:textfield name="keywords.pinyin" maxlength="50" cssClass="txtin"/>
				<span style="color:red" id="span_pinyin"></span>
				</td>
			</tr>
			<tr>
				<th><span style="color:red;">*</span><s:text name="keywords.splitWords"/>:</th>
				<td>
				<s:textfield name="keywords.splitWords" maxlength="60" cssClass="txtin"/>
				<span style="color:red" id="span_splitWords"></span>
				</td>
			</tr>
			<tr>
				<th><s:text name="keywords.isenable"/>:</th>
				<td>
				<s:checkbox name="keywords.isEnable"></s:checkbox>启用
				</td>
			</tr>
						
			<tr>
				<th>&nbsp;</th>
				<td><s:submit value="%{getText('save')}" cssClass="btnlist2"/>
				<s:reset value="%{getText('reset')}" cssClass="btnlist2"/>
				<input type="button" value="<s:text name='return'/>" class="btnlist2" onclick="history.back()">
				</td>
			</tr>
		</table>
		</s:form>
	</div>
</div>
</body>
</html>
<script type="text/javascript" defer="defer">
	function chkform(){
		var word = $.trim($("input[name='keywords.keywords']").val());
		var szm = $.trim($("input[name='keywords.firstLetter']").val());
		var py = $.trim($("input[name='keywords.pinyin']").val());
		var fc = $.trim($("input[name='keywords.splitWords']").val());
		var regex = /^[a-zA-Z0-9]{1,}$/;
		if($.trim(word)==''){
			$("#span_keywords").html("不能为空");
			return false;
		}
		if($.trim(szm)==''){
			$("#span_firstLetter").html("不能为空");
			return false;
		}
		else if(!regex.test(szm)){
			$("#span_firstLetter").html("格式不正确");
			return false;
		}
		if($.trim(py)==''){
			$("#span_pinyin").html("不能为空");
			return false;
		}
		else if(!regex.test(py)){
			$("#span_pinyin").html("格式不正确");
			return false;
		}
		if($.trim(fc)==''){
			$("#span_splitWords").html("不能为空");
			return false;
		}
		return true;
				
	}
	function chk_words(){
		var keyword = $("input[name='keywords.keywords']").val();
		var id = $("input[name='keywords.keywordsId']").val();
		if($.trim(keyword)==''){
			$("#span_keywords").html("不能为空");
			return false;
		}
		else{
			var flag = false;
			$.ajax({
				type:"POST",
				async:false,
				url:"keywords-checkwords.action?random="+Math.random(),
				data:{'keywords.keywordsId':$.trim(id),'keywords.keywords':$.trim(keyword)},
				success:function(data){
					var json = eval('('+data+')');
					flag = json.flag;					
				}
			});
			
			if(flag){
				$("#span_keywords").html("已经存在!");
				return false;
			}
			else{
				$.ajax({
					type:"POST",
					async:false,
					url:"keywords-getwords.action?random="+Math.random(),
					data:{'keywords.keywords':keyword},
					success:function(data){
						var json = eval('('+data+')');
						$("input[name='keywords.firstLetter']").val(json.szm);
						$("input[name='keywords.pinyin']").val(json.py);
						$("input[name='keywords.splitWords']").val(json.fc);
					}
				});
				return true;
			}
			
		}		
	}
</script>